package com.ruoyi.web.controller.modules;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.incomeexpense.ZQEmail;
import com.ruoyi.web.pojo.request.incomeexpense.EmailAddReq;
import com.ruoyi.web.pojo.request.incomeexpense.EmailUpDateReq;
import com.ruoyi.web.service.incomeexpense.IZQEmailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 邮箱发送记录Controller
 * 
 * @author zq
 * &#064;date  2024-01-13
 */
@Api(tags = "邮箱发送记录")
@RestController
@RequestMapping("/system/email")
public class ZQEmailController extends BaseController
{
    private final IZQEmailService zQEmailService;

    public ZQEmailController(IZQEmailService zQEmailService) {
        this.zQEmailService = zQEmailService;
    }

    /**
     * 查询邮箱发送记录列表
     */
    @ApiOperation("查询邮箱发送记录列表")
    @GetMapping("/list")
    public TableDataInfo<ZQEmail> list(ZQEmail zQEmail)
    {
        startPage();
        List<ZQEmail> list = zQEmailService.selectZQEmailList(zQEmail);
        return getDataTable(list);
    }

    @ApiOperation("获取最新一次邮箱记录")
    @GetMapping("/getLastOne")
    public AjaxResult getLastOne(){
        return AjaxResult.success(zQEmailService.getLastOne());
    }

    /**
     * 导出邮箱发送记录列表
     */
    @ApiOperation("导出邮箱发送记录列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZQEmail zQEmail)
    {
        List<ZQEmail> list = zQEmailService.selectZQEmailList(zQEmail);
        ExcelUtil<ZQEmail> util = new ExcelUtil<>(ZQEmail.class);
        util.exportExcel(response, list, "邮箱发送记录数据");
    }

    /**
     * 获取邮箱发送记录详细信息
     */
    @ApiOperation("获取邮箱发送记录详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zQEmailService.selectZQEmailById(id));
    }

    /**
     * 新增邮箱发送记录
     */
    @ApiOperation("新增邮箱发送记录")
    @PostMapping
    public AjaxResult add(@RequestBody EmailAddReq req)
    {
        return toAjax(zQEmailService.insertZQEmail(EmailAddReq.toEmail(req)));
    }

    /**
     * 修改邮箱发送记录
     */
    @ApiOperation("修改邮箱发送记录")
    @PutMapping("/{id}")
    public AjaxResult edit(@PathVariable("id") Long id,@RequestBody EmailUpDateReq req)
    {
        ZQEmail email = EmailUpDateReq.toEmail(req);
        email.setId(id);
        email.setUserId(SecurityUtils.getUserId());
        return toAjax(zQEmailService.updateZQEmail(email));
    }

    /**
     * 删除邮箱发送记录
     */
    @ApiOperation("删除邮箱发送记录")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zQEmailService.deleteZQEmailByIds(ids));
    }
}
